﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace TypingG
{
    class tBoxStyle2:tBox
    {
        
        private Timer timer1 = new Timer();
      
        public tBoxStyle2()
        {

        }
        public override void getStyle()
        {
            string content = StringRandom.getStRandom(300);
            LabelCollection(content);
            int distancex = 20;
            int distancey = 20;
            int endtoenter = this.Width / distancex;
            for (int i = 0; i < arrLabel.Count; i++)
            {
                int div = (i * distancex) / this.Width;
                int du = i % endtoenter;
                ((Label)arrLabel[i]).Location = new System.Drawing.Point(distancex * du, 20 + distancey * div);
                this.Controls.Add(((Label)arrLabel[i]));
            }
            this.KeyPress += new KeyPressEventHandler(tBoxStyle3_KeyPress);
            processbar();

            timer1.Start();
            timer1.Interval = 100;
            this.delay = StringRandom.Speed / timer1.Interval;
            timer1.Tick += new EventHandler(timer1_Tick);
                
        }
        private int _index = 0;
        void tBoxStyle3_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (Convert.ToString(e.KeyChar) == ((Label)this.arrLabel[_index]).Text)
            {

                this.Clear();
                ((Label)this.arrLabel[_index]).ForeColor = System.Drawing.Color.Red;
                if (_index == 299)
                {
                    timer1.Stop();
                    AccInfo.increaseEXP(AccInfo.WILLHAVEEXP);
                    MessageBox.Show("YouWin.You Have " + Convert.ToString(AccInfo.WILLHAVEEXP) + " EXP");
                    this.Dispose();
                }
                _index++;
            }
            else
            {
                this.Clear();
                for (int i = 0; i <= _index; i++) ((Label)this.arrLabel[i]).ForeColor = System.Drawing.Color.White;
                _index = 0;

            }


        }
        private int delay;
        private int m = 0;
        void timer1_Tick(object sender, EventArgs e)
        {

            this.Focus();
            if (m == this.delay)
            {
                this.pBar.Increment(1);
                m = 0;
            }
            if (this.pBar.Value == this.pBar.Maximum)
            {
                timer1.Stop();
                
                MessageBox.Show("YouLose.You Have 0 EXP");
                this.Dispose();
            }
            m++;
        }
        
    }
}
